package web.controller.sys;

import com.github.pagehelper.PageInfo;
import framework.vo.ResultInfo;
import framework.vo.ResultList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import system.entity.SysLogin;
import system.service.sys.SysLoginService;

import java.util.List;

@RestController
@RequestMapping("/sys/login")
@Api(tags = "登录记录")
public class SysLoginController {
    @Autowired
    private SysLoginService sysLoginService;

    @ApiOperation("添加登录记录")
    @PostMapping("/add")
    public ResultInfo<Integer> add(@ModelAttribute SysLogin param) {
        Integer added = sysLoginService.add(param);
        ResultInfo<Integer> info = new ResultInfo<>(added);
        return info;
    }

    @ApiOperation("删除登录记录")
    @PostMapping("/del")
    public ResultInfo<Integer> del(@RequestParam("ids") List<Long> ids) {
        Integer deleted = sysLoginService.deleteByIds(ids);
        ResultInfo<Integer> info = new ResultInfo<>(deleted);
        return info;
    }

    @ApiOperation("更新登录记录")
    @PostMapping("/edit")
    public ResultInfo<Integer> edit(@ModelAttribute SysLogin param) {
        Integer updated = sysLoginService.update(param);
        ResultInfo<Integer> info = new ResultInfo<>(updated);
        return info;
    }

    @ApiOperation("查看登录记录")
    @GetMapping("/info")
    public ResultInfo<SysLogin> info(@RequestParam("id") Long id) {
        SysLogin info = sysLoginService.loadById(id);
        return new ResultInfo<>(info);
    }

    @ApiOperation("列表")
    @GetMapping("/list")
    public ResultList<SysLogin> list(SysLogin param, @RequestParam(value = "pageIndex", defaultValue = "1") Integer pageIndex, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<SysLogin> info = sysLoginService.list(param, pageIndex, pageSize);
        return new ResultList<>(info);
    }

}